package com.deryun.tyl.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.deryun.tyl.bean.User;
import com.deryun.tyl.bean.mapper.UserMapper;
import com.deryun.tyl.dao.impl.UserDaoImpl;

@Service(value="userService")
public class UserServiceImpl {

	@Resource(name = "userDao")
	private UserDaoImpl userDao;
	
	public User getUserByUsername(String username) {
		return userDao.getUserByUsername(username);
	}

	public User doLogin(String username, String password) {
		return userDao.doLogin(username, password);
	}

	public int addUser(User user){
		String username = user.getUsername();

		//设置注册日期为当前日期
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		user.setDate(df.format(new Date()));
		//判断用户权限类型
		String role = user.getRole();
		if (role.equals("1")) {
			user.setRole("A");
		}else if (role.equals("2")) {
			user.setRole("B");
		}else if (role.equals("3")) {
			user.setRole("C");
		}else if (role.equals("4")) {
			user.setRole("D");
		}else if (role.equals("5")) {
			user.setRole("E");
		}
		if (user.getInstitutionBankAuth()==null) {
			user.setInstitutionBankAuth("0");
		}
		if (user.getInstitutionOnekeyAuth()==null) {
			user.setInstitutionOnekeyAuth("0");
		}
		user.setAccountAuth("0");
		int res = userDao.addUser(user);
		if (res > 0) {
			return res;
		}else {
			return 0;
		}
	}

	
	public User validateNames(User user){
		return userDao.validateUser(user);
	}
	
	public int getNewId(){
		return userDao.getNewId();
	}
	
	public int authInstitution(User tuser){
		return userDao.authInstitution(tuser);
	}
	
	public int authOneKey(String id){
		return userDao.authOneKey(id);
	}
	
	public int authBank(String id){
		return userDao.authBank(id);
	}
	
	public List<User> getAllUser(){
		return userDao.getAllUser();
	}
	
	public User getUserById(int id){
		return userDao.getUserById(id);
	}
	
	public List<User> searchUser(String role,String institutionName){
		return userDao.searchUser(role, institutionName);
	}
	
	public int modifyUser(User user){
		return userDao.modifyUser(user);
	}
	
	public int accessAuth(User user){
		return userDao.accessAuth(user);
	}
	
	public List<User> searchAuth(String auth,String institutionName){
		return userDao.searchAuth(auth, institutionName);
	}
	
	public int toFrontSupplier(int id){
		return userDao.toFrontSupplier(id);
	}
	
	public int toOneKeySupplier(int id){
		return userDao.toOneKeySupplier(id);
	}
	
	public int removeFrontSupplier(int id){
		return userDao.removeFrontSupplier(id);
	}
	
	public int removeOneKeySupplier(int id){
		return userDao.removeOneKeySupplier(id);
	}

	public int getCountFront(){
		return userDao.getCountFront();
	}
	
	public int getCountOneKey(){
		return userDao.getCountOneKey();
	}
	
	public List<User> getFrontSupplier(){
		return userDao.getFrontSupplier();
	}
	
	public List<User> getOneKeySupplier(){
		return userDao.getOneKeySupplier();
	}
}
